package example2;

public class OrderServive {

    public static Order addOrder(User user, Item[] items) {
        double allcost = 0;
        for (Item item : items) {
            allcost += item.getProduct().getPrice() * item.getAmount();
        }

        if (user.getBalance() >= allcost) {
            Order order = new Order(user, items, allcost);
            return order;
        }
        else {
           return null;
        }
    }
}










